package com.lgy.web.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by fengch on 2017/5/29.
 */
@Controller
@RequestMapping("/systemController")
public class SystemController {
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "/html/system/login";
    }

    @RequestMapping("/toLogout")
    public String toLogout(HttpServletRequest request, HttpServletResponse response)  {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null){
            new SecurityContextLogoutHandler().logout(request, response, auth);
        }
        return "index";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(@RequestParam(value = "error", required = false) String error,
                        @RequestParam(value = "logout", required = false) String logout)  {
        System.out.println("aaaaaaaaaaaaaaaaa");
        return "index";
    }
}
